package com.menhai.personmanagement.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.menhai.personmanagement.entity.HealthEncyclopediaDirectory;
import com.menhai.personmanagement.entity.HealthEncyclopediaPage;
import com.menhai.personmanagement.mapper.HealthEncyclopediaPageMapper;
import com.menhai.personmanagement.utils.UuidUtil;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/HealthEncyclopediaPage")
public class HealthEncyclopediaPageController {
	@Autowired
	private HealthEncyclopediaPageMapper HealthEncyclopediaPageMapper;
	
	//初始化目录
	@RequestMapping("/directory")
	public List<HealthEncyclopediaDirectory> directory (HealthEncyclopediaDirectory HealthEncyclopediaDirectory){
		List<HealthEncyclopediaDirectory> HealthEncyclopediaDirectoryList = new ArrayList<HealthEncyclopediaDirectory>();
		HealthEncyclopediaDirectoryList = directoryMapper(HealthEncyclopediaDirectory);
	    return HealthEncyclopediaDirectoryList;
	 }
	@RequestMapping("/template")
	public List<HealthEncyclopediaPage> template (HealthEncyclopediaPage HealthEncyclopediaPage){
		List<HealthEncyclopediaPage> HealthEncyclopediaPageList = new ArrayList<HealthEncyclopediaPage>();
		HealthEncyclopediaPageList = templateMapper(HealthEncyclopediaPage);
	    return HealthEncyclopediaPageList;
	 }
	//新建保存
	@RequestMapping("/del")
	public Object del(HealthEncyclopediaPage HealthEncyclopediaPage) throws Exception{
		HealthEncyclopediaPage.setTemplate_id(UuidUtil.uuid());
		 return delMapper(HealthEncyclopediaPage);
	}
	//删除
	@RequestMapping("/delete")
	public Object delete(HealthEncyclopediaPage HealthEncyclopediaPage) throws Exception{
		return deleteMapper(HealthEncyclopediaPage); 
	}
	//编辑
	@RequestMapping("/dels")
	public Object dels(HealthEncyclopediaPage HealthEncyclopediaPage) throws Exception{
		return delsMapper(HealthEncyclopediaPage); 
	   }
	public List<HealthEncyclopediaDirectory> directoryMapper(HealthEncyclopediaDirectory HealthEncyclopediaDirectory) {
		return HealthEncyclopediaPageMapper.directory(
				HealthEncyclopediaDirectory.getSelect_identity(),
				HealthEncyclopediaDirectory.getParent_list_id()
			);
	}
	public List<HealthEncyclopediaPage> templateMapper(HealthEncyclopediaPage HealthEncyclopediaPage) {
		return HealthEncyclopediaPageMapper.template(HealthEncyclopediaPage.getSelect_identity(),HealthEncyclopediaPage.getParent_template_id());
	}
	public Map<String, Object> delMapper(HealthEncyclopediaPage HealthEncyclopediaPage) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
  		int iRet = HealthEncyclopediaPageMapper.del(HealthEncyclopediaPage);
  		if(iRet == 0){  //没有插入成功的数据
				resultMap.put("success", "0");
				resultMap.put("message", "插入成功的条数为0，新建健康百科内容失败！");
				return resultMap;
			}else{
				resultMap.put("success", "1");
				resultMap.put("message", "新建健康百科内容成功！");
				return resultMap;
			}
	}
	public Map<String, Object> deleteMapper(HealthEncyclopediaPage HealthEncyclopediaPage) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
  		int iRet = HealthEncyclopediaPageMapper.delete(HealthEncyclopediaPage);
  		if(iRet == 0){  //没有插入成功的数据
				resultMap.put("success", "0");
				resultMap.put("message", "插入成功的条数为0，删除健康百科内容失败！");
				return resultMap;
			}else{
				resultMap.put("success", "1");
				resultMap.put("message", "删除健康百科内容成功！");
				return resultMap;
			}
	}
	public Map<String, Object> delsMapper(HealthEncyclopediaPage HealthEncyclopediaPage) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
  		int iRet = HealthEncyclopediaPageMapper.dels(HealthEncyclopediaPage);
  		if(iRet == 0){  //没有插入成功的数据
				resultMap.put("success", "0");
				resultMap.put("message", "插入成功的条数为0，编辑健康百科内容失败！");
				return resultMap;
			}else{
				resultMap.put("success", "1");
				resultMap.put("message", "编辑健康百科内容成功！");
				return resultMap;
			}
	}
	
}
